package com.scau.clothes.controller;

import com.scau.clothes.pojo.OrderClothes;
import com.scau.clothes.pojo.User;
import com.scau.clothes.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//公共页面的congroller
//如index input
@Controller
public class IndexController {
    @Autowired
    CartService cartService;
    @RequestMapping("input")
    public ModelAndView toInputPage(HttpServletRequest request){
        User user = (User) request.getAttribute("user");
        ModelAndView mv = new ModelAndView();
        int userId = user.getId();
        List<OrderClothes> ocList = cartService.getOCByUserIdInRedis(userId);
        mv.addObject("ocList",ocList);
        mv.setViewName("input");
        return mv;
    }
    @RequestMapping("toIndex")
    public ModelAndView toIndexPage(HttpServletRequest request){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("public/index");
        return mv;
    }
    @RequestMapping("/toChat")
    public ModelAndView toChat(String to){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("chat");
        System.out.println(to);
        return mv;
    }
}
